package com.ymttest.business.data;

import java.math.BigDecimal;
import java.util.Arrays;

import com.ymatou.iapi.optrade.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.optrade.parameter.vo.OrderGroupVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderItemVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderVo;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;

public class Order {
	 private static void setPrice(AddSellerProductRequest addpro, Double price) {
	        addpro.getProduct().getCatalogList().forEach(catalog -> {
	            catalog.setNewPrice(price);
	            catalog.setMarketPrice(price);
	            catalog.setVipPrice(price);
	            catalog.setPrice(price);
	        });
	    }
public static void main(String args[]) throws Exception {
	Long userId=Long.valueOf(EnvSetup.getData("BuyUserId"));
	Long sellerId=Long.valueOf(EnvSetup.getData("autotest_seller1"));
	AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId.intValue());
	Order.setPrice(addpro, 1d);
	String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
	BigDecimal price=new BigDecimal(1d);
	
	String catalogId = new YmtCatalogsIWapper().selectCatalogsByProductId(pid).get(0).getsCatalogId();
	
	PlaceOrderReq req = TradingCallService.buildStandPlaceOrderReq();
	
	OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, "sellerName");
	OrderVo orderVo = TradingCallService.createOrderVo();
	
	OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
			pid, catalogId);
	
	orderItemVo.setProductPrice(price);
	
	orderVo.setOrderItems(Arrays.asList(orderItemVo));
	orderGroupVo.setOrders(Arrays.asList(orderVo));
	req.setOrderGroups(Arrays.asList(orderGroupVo));
	
	req.withUserId(userId);
	
	TradingCallService.callPlaceOrderService(req);
	System.out.println("TradingServiceResp:"+FormatUtil.beanToGSONString(req));
}
}
